package com.oocl.commandProcess;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.util.Scanner;

import com.oocl.printFormat.PrintFormat;

public class CommandProcess {
	
	CommandParse commandparse;
	PrintFormat pf;
	
	public CommandProcess(){
		commandparse = new CommandParse();
		pf = new PrintFormat();
	}
	
	public void process(InputStream in, OutputStream out) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		String command = reader.readLine();
		String com = commandparse.parse(command);
		if("conmand1".equals(com)){
			out.write(pf.printXML().getBytes());
		}else if("command2".equals(com)){
			out.write(pf.printByBirth().getBytes());
		}else if("command3".equals(com)){
			FileOutputStream fout = new FileOutputStream("xmlById.txt");
			fout.write(pf.printXML().getBytes());
		}else if("error".equalsIgnoreCase(com)){
			out.write("command error!\r\n".getBytes());
		}
	}
}
